/**
 * Course Project for User Interface Programming I, 2011
 * Group 19
 */
package justdoit.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import justdoit.controller.TaskManager;
import justdoit.model.Task;
import justdoit.controller.LanguageManager;
import justdoit.controller.IconManager;

/**
 * 
 * @author Can
 */
public class MarkAsDoneAction extends AbstractAction {

    public MarkAsDoneAction() {
        super(LanguageManager.getString("menu.task.markAsDone"), IconManager.getIcon("doneTask.png"));
        putValue(MNEMONIC_KEY, LanguageManager.getMnemonic("mnemonic.menu.task.mark"));
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("control M"));
        putValue(MNEMONIC_KEY, KeyEvent.VK_D);
    }

    public MarkAsDoneAction(String text) {
        super(text);
    }

    public MarkAsDoneAction(String text, ImageIcon icon) {
        super(text, icon);
    }

    public MarkAsDoneAction(String text, ImageIcon icon,
            String desc, Integer mnemonic) {
        super(text, icon);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
    }

    public void actionPerformed(ActionEvent e) {
        Task selectedTask = justdoit.Startup.getMainFrame().getTaskListPanel().getSelectedTask();
        if (selectedTask != null) {
            String message = LanguageManager.getString("confirmDialogMarkAsDone");
            int result = JOptionPane.showConfirmDialog(null, message,
                    LanguageManager.getString("titleMarkAsDone"), JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.NO_OPTION) {
                return;
            }
            if (TaskManager.markAsDone(selectedTask) == 0) {
                justdoit.Startup.getMainFrame().getTaskListPanel().refreshData();
            }
        } else {
            System.out.println("selectedTask == null. markAsDone");
        }
    }
}
